public class DocumentHeader : Gtk.HBox
{
	private Gtk.Button close_btn;
	private Gtk.Label  title_lbl;
	
	private static int count = 0;
	private weak Document doc = null;

	construct 
	{
		this.close_btn = Utils.create_small_button (
				new Gtk.Image.from_stock (Gtk.STOCK_CLOSE, Gtk.IconSize.MENU)
			    );
		this.title_lbl = new Gtk.Label ("");	    		
		this.pack_start_defaults (title_lbl);
		this.pack_start_defaults (close_btn);
		this.show_all ();	    
	}
	
	public DocumentHeader (string? filename, ref Document doc)
	{	
		this.doc = doc;
		this.close_btn.clicked += this.on_close_btn_clicked;
		if (filename == null)
		{
			++count;
			this.text = "Nowy plik " + count.to_string ();
		}
		else
		{
			this.text = GLib.Path.get_basename (filename);	
		}
	}
	
	public string text 
	{
		get { return title_lbl.get_text (); }
		set { title_lbl.set_text (value);   }
	}
	
	public void set_state (Document.DocumentState state)
	{
		Gdk.Color? c = null;
		switch (state) {
			case Document.DocumentState.NO_MODIFIED: {
				Gdk.Color.parse ("#000000", out c);
			} break;
			case Document.DocumentState.MODIFIED: {
				Gdk.Color.parse ("#dd0000", out c);
			} break;
			case Document.DocumentState.READ_ONLY: {
				Gdk.Color.parse ("silver", out c);
			} break;
		}
		this.title_lbl.modify_fg (Gtk.StateType.ACTIVE, c);
		this.title_lbl.modify_fg (Gtk.StateType.NORMAL, c);
	}
	
	protected void on_close_btn_clicked ()
	{
		if (this.doc.close ())
		{
			this.doc.destroy ();
		}		
	}	
}
